import { history, useModel } from '@umijs/max';
import { useEffect } from "react";

export default function (){
  const {data} = useModel('user');

  useEffect(()=>{
    if(data.resourceList?.length){
      function findFirstMenu(list: API.ResourceListVo[]): API.ResourceListVo | undefined{
        list.forEach(item=>{
          if(item.type === 'MENU'){
            return item;
          }
          if(item.children?.length){
            return findFirstMenu(item.children);
          }
        })

        return undefined;
      }

      const firstMenu = findFirstMenu(data.resourceList);

      if(firstMenu){
        history.push(firstMenu.path!)
      }

    }
  },[data])

  return <></>
}
